<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="用户名" prop="field101">
        <el-input v-model="formData.field101" placeholder="请输入用户名" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="密码" prop="field102">
        <el-input v-model="formData.field102" placeholder="请输入密码" clearable show-password
          :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label-width="130px" label="感兴趣的教程" prop="field103">
        <el-select v-model="formData.field103" placeholder="请选择感兴趣的教程" multiple filterable clearable
          :style="{width: '100%'}">
          <el-option v-for="(item, index) in field103Options" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        field101: undefined,
        field102: undefined,
        field103: [],
      },
      rules: {
        field101: [{
          required: true,
          message: '请输入用户名',
          trigger: 'blur'
        }],
        field102: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur'
        }],
        field103: [{
          required: true,
          type: 'array',
          message: '请至少选择一个field103',
          trigger: 'change'
        }],
      },
      field103Options: [{
        "label": "健身",
        "value": 1
      }, {
        "label": "游泳",
        "value": 2
      }, {
        "label": "网球",
        "value": 3
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
        const path = '/mypath'
          axios.post(path,{
            name:this.formData.field101
          }).then(response=>{
            console.log(response);
          }).catch(err =>{
            console.log(err);
          });
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
  }
}

</script>

<style>
</style>
